<?php
namespace app\admin\controller;

use app\model\SystemUser;
use support\Request;
use think\facade\Db;

class Login
{
    public function login(Request $request){
        $param = $request->post();
        if(empty($param['username']) || empty($param['password'])){
            return error('用户名或密码不能为空');
        }

        $result = SystemUser::where('username', $param['username'])->where('password', md5($param['password']))->find();
        if(empty($result)){
            return error('用户名或密码错误');
        }

        $jwtToken = new \Token();
        $returnjwt = $jwtToken->createToken([
            'id' => $result['id']
        ]);
        if($returnjwt['status'] == 200){
            $return['token'] = $returnjwt['token'];
        }else{
            return error('登录错误');
        }

        return success($return, '登录成功');
    }

	public function info()
	{
		$where= ['system_web_logo','system_web_name','system_web_miitbeian','system_web_copyright'];
		$data = Db::name('SystemConfig')->whereIn('name',$where)->column('value','name');
		return success([
			'webLogo'=>$data['system_web_logo'],
			'webName'=>$data['system_web_name'],
			'webMiitbeian'=>$data['system_web_miitbeian'],
			'webCopyright'=>$data['system_web_copyright']
		]);
	}

}
